<?php

namespace App\Admin\Controllers;

use App\Models\Consensus;
use App\Models\Scene;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class ConsensusController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('舆论');
            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('编辑');
            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('新建');
            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Consensus::class, function (Grid $grid) {
            $grid->actions(function ($actions) {
                $actions->disableView();
            });
            $grid->disableExport();
            $grid->id('ID')->sortable();
            $grid->type('类型')->using(config('options.consensus_type'));
            $grid->source('来源')->using(config('options.consensus_source'));
            $grid->scene_id('景区')->using(Scene::where('is_docking',1)->pluck('title','id')->toArray());
            $grid->content('关键词');
            $grid->commnet_num('数量');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Consensus::class, function (Form $form) {
            $form->select('scene_id', '景区')->options(Scene::where('is_docking',1)->pluck('title','id'));
            $form->select('type', '类型')->options(config('options.consensus_type'));
            $form->select('source', '来源')->options(config('options.consensus_source'));
            $form->number('commnet_num','数量');
            $form->tags('content','关键词');
        });
    }
}
